﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using myframework._99_热身.time._2011_10_24_scm;
using Webdiyer.WebControls.Mvc;

namespace MvcApplication1.Controllers
{
    public class CityController : Controller
    {
        public ActionResult Page(int? id)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();
            var lc = dc.City.AsEnumerable().Distinct(new JuryComparer()).AsQueryable().Select(m => m).ToPagedList(id ?? 1, 10);
            return View(lc);
        }

        //
        // GET: /City/

        public ActionResult Index(int? id)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();
            var lc = dc.City.AsEnumerable().Distinct(new JuryComparer()).AsQueryable().Select(m => m).ToPagedList(id ?? 1, 10);
            return View(lc);
        }

        public class JuryComparer : IEqualityComparer<City>
        {
            public bool Equals(City x, City y) { return x.CityName.Equals(y.CityName); }

            public int GetHashCode(City obj) { return 0; }
        }

        //
        // GET: /City/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /City/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /City/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /City/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /City/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /City/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /City/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}